package com.hj.aimin.drug.controller;


import com.hj.aimin.base.response.Result;
import com.hj.aimin.drug.service.DrugService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/drug")
@RequiredArgsConstructor
public class DrugController {

    public final DrugService drugService;

    @GetMapping("/categoryId/{categoryId}")
    public Result<?> findDrugByCategoryId(@PathVariable Integer categoryId){
        return Result.success(drugService.findByCategoryId(categoryId));
    }


    @RequestMapping("/getAll")
    public Result<?> getAll(){
        return Result.success(drugService.list());
    }


    @RequestMapping("/getById")
    public Result<?> getById(@RequestParam String id){
        return Result.success(drugService.getById(id));
    }

    @RequestMapping("/{id}")
    public Result<?> getByID1(@PathVariable Integer id){
        return Result.success(drugService.getById(id));
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable String id){
        return Result.success(drugService.removeById(id));
    }

}
